<template>
  <div class="Login">
    <noLogHeader></noLogHeader>
    <!-- <el-button type="primary" plain @click="$router.push('/home')">登录页</el-button> -->
    <div class="main center">
      <div class="body bCFF flex">
        <img src="/src/assets/image/zcbj.png" alt="" class="body_img">
        <div class="body_view">
          <div class="body_view_top">
            <div class="between">
              <div class="tab items column" v-for="(item, index) in list" @click="tabClick(item.index)">
                <div class="tab_name">{{ item.name }}</div>
                <div class="tab_line mTop12" :class="indexOf == index+'' ? 'tab_line_1' : ''"></div>
              </div>
            </div>
          </div>
          <div class="body_view_btm">
            <div class="tabBox tab-one" v-if="indexOf !== '0'">
              <el-input class="input_view mTop20" v-model="state.mobile.mobile" placeholder="Введите номер телефона" />
              <el-input class="input_view mTop20" v-model="state.mobile.mobileCode" placeholder="Код проверки" >
                <template #append>
                  <div class="captcha" @click="codeTimeFun">{{ state.codeNum !== 60 ? state.codeNum + 's' : 'проверки' }}</div>
                </template>
              </el-input>
            </div>
            <div class="tabBox tab-tow" v-else>
              <el-input class="input_view mTop20" v-model="state.emailObj.email" placeholder="Введите почтовый ящик" />
              <el-input class="input_view mTop20" v-model="state.emailObj.emailCode" placeholder="Код проверки" >
                <template #append>
                  <div class="captcha" @click="codeTimeFun">{{ state.codeNum !== 60 ? state.codeNum + 's' : 'проверки' }}</div>
                </template>
              </el-input>
              <el-input class="input_view mTop20" v-model="state.emailObj.password" placeholder="Введите пароль" type="password"/>
              <el-input class="input_view mTop20" v-model="state.agnPassword" placeholder="Введите пароль снова" type="password"/>
            </div>

            <div class="mTop40">
              <div class="login_btn center cFF" @click="signInFun">Регистрация</div>
              <div class="login_note between">
                <div>
                  <span>Уже есть аккаунт?</span>
                  <span style="color:#0070E9;;cursor: pointer" @click="$router.push('/login')">Войти в систему</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog v-model="state.dialogTableVisible" width="514" :show-close="false" :align-center="true" :close-on-click-modal="false" :close-on-press-escape="false">
      <div class="dialogBox">
        <div class="title">Регистрация успешно</div>
        <div class="tip">Для безопасности вашей учетной записи рекомендуется привязать почтовый ящик.</div>
        <div class="dialogBtn">
          <div class="dialogBtnText btn-left" @click="$router.push('/home')">Иди погуляй</div>
          <div class="dialogBtnText btn-right" @click="$router.push('/home')">Перейти к <br>привязке</div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script lang="ts" name="Login" setup>
import { ref, reactive,onMounted } from "vue";
import { UserData } from "@/base";
import { useRouter } from 'vue-router'
import useUserStore from '@/store/modules/user'
import noLogHeader from '../../components/Header/noLogHeader.vue';//引入的头部的主键

const router = useRouter()
const userStore = useUserStore()
const indexOf = ref('0');
const list = ref([
  {
    index:'0',
    name: 'Регистрация почтового ящика',
  },
  {
    index:'1',
    name: 'Мобильные телефоны',
  },
])


const tabClick = (index: string) => {
  indexOf.value = index
}
// //定义对象
const state = reactive({
  userInfo: [] as UserData[],
  total: 0,
  dialogTableVisible:false,
  codeNum:60,
  codeTime:undefined,
  mobile:{
    mobile:'',
    mobileCode:''
  },

  emailObj:{
    email:'',
    emailCode:'',
    password:'',
  },
  agnPassword:''
})
const codeTimeFun = () => {
  if(state.codeNum === 60){
    state.codeTime = setInterval(() => {
      state.codeNum --
      if (state.codeNum === 0){
        clearTimeout(state.codeTime)
        state.codeNum = 60
      }
    },1000)
  }

}
const signInFun = () => {
  userStore.signIn(indexOf.value, state)
}

onMounted(() => {

})


</script>

<style lang="less" scoped>
.Login {

  .main {
    width: 100%;
    height: 82vh;
    background-color: #F0EFF2;

    .body {
      width: 1000px;
      height: 560px;
      border-radius: 16px;

      &_img {
        width: 517px;
        height: 560px;
        border-radius: 16px 0 0 16px;
      }

      &_view {
        &_top {
          height: 107px;
          width: 483px;
          border-bottom: 1px solid #EEEEEE;
          display: flex;
          align-items: flex-end;
          justify-content: center;

          .tab {
            text-align: center;

            &_name {
              width: 155px;
              height: 32px;
              font-family: PingFang SC;
              font-size: 16px;
              font-weight: 600;
              line-height: 16px;
              cursor: pointer;
            }

            &_line {
              width: 84px;
              height: 3px;
              border-radius: 2px;
            }

            &_line_1 {
              background: #0070E9;
            }
          }
        }

        &_btm {
          height: 422px;
          width: 351px;
          padding: 0 66px 0 66px;
          .tabBox{
            margin-top: 11px;
            :deep(.el-input-group__append){
              box-shadow: none;
            }
          }
          .input_view {
            height: 44px;
            color: #2C5AA7;
            border-radius: 8px;
            background-color: #F3F6F8;

            ::v-deep .el-input__wrapper {
              box-shadow: none;
              background-color: #F3F6F8;
            }

            .captcha{
              //box-sizing: border-box;
              //padding: 15px 0;
              padding-left: 26px;
              height: 16px;
              display: flex;
              align-items: center;
              border-left: 1px solid #0070E9;
              font-family: PingFang SC, PingFang SC;
              font-weight: 500;
              font-size: 14px;
              color: rgba(0, 112, 233, 0.8);
              text-align: right;
              font-style: normal;
              text-transform: none;
              cursor: pointer;
            }
          }

          .login_btn {
            width: 350px;
            height: 48px;
            border-radius: 8px;
            font-family: PingFang SC;
            font-size: 14px;
            font-weight: 400;
            line-height: 14px;
            background: #0070E9;
            cursor: pointer;
          }

          .login_note {
            font-family: PingFang SC, PingFang SC;
            font-weight: bold;
            font-size: 12px;
            color: #999999;
            font-style: normal;
            text-transform: none;
            text-align: center;
            justify-content: center;
            margin-top: 20px;
          }
        }
      }
    }
  }
  :deep(.el-dialog){
    padding: 0;
    box-shadow:none;
    border-radius: 16px;
  }
  :deep(.el-dialog__header){
    padding: 0;
  }
  .dialogBox{
    width: 514px;
    height: 308px;
    overflow: hidden;
    background-image: url('/src/assets/image/dialogImg.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    align-items: center;
    .title{
      margin-top: 143px;
      text-align: center;
      font-family: PingFang SC, PingFang SC;
      font-weight: bold;
      font-size: 18px;
      color: #333333;
      line-height: 18px;
      font-style: normal;
      text-transform: none;
    }
    .tip{
      width: 418px;
      //height: 42px;
      background: #ECF3FF;
      border-radius: 4px 4px 4px 4px;
      box-sizing: border-box;
      padding: 8px 21px;
      margin-top: 17px;
      font-family: PingFang SC, PingFang SC;
      font-weight: 500;
      font-size: 13px;
      color: #0070E9;
      line-height: 13px;
      text-align: left;
      font-style: normal;
      text-transform: none;
    }
    .dialogBtn{
      display: flex;
      margin-top: 20px;
      .dialogBtnText{
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
      }
      .btn-left{
        width: 199px;
        height: 48px;
        background: #F6F7FB;
        border-radius: 10px 10px 10px 10px;
        border: 1px solid #CCCCCC;
        margin-right: 10px;
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 14px;
        color: #333333;
        line-height: 14px;
        text-align: center;
        font-style: normal;
        text-transform: none;
      }
      .btn-right{
        width: 199px;
        height: 48px;
        background: #0070E9;
        border-radius: 10px 10px 10px 10px;
        margin-left: 10px;
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 14px;
        color: #FFFFFF;
        line-height: 14px;
        text-align: center;
        font-style: normal;
        text-transform: none;
      }
    }
  }

}
</style>
